package com.itheima.controller.v1;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.common.R;
import com.itheima.controller.v1.api.CluesControllerApi;
import com.itheima.dto.ClueQueryDto;
import com.itheima.pojo.TbActivity;
import com.itheima.pojo.TbClue;
import com.itheima.service.TbActivityService;
import com.itheima.service.TbClueService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/clues")
@Slf4j
public class CluesController implements CluesControllerApi {
    @Autowired
    private TbActivityService tbActivityService;

    @Autowired
    private TbClueService tbClueService;

    @Override
    @GetMapping("/activity/listselect/{channel}")
    public R listselect(@PathVariable String channel) {
        log.info("获取渠道来源方法");
        return tbActivityService.getByChannel(channel);
    }

    @PostMapping("/clue")
    @Override
    public R add(TbClue tbClue) {


        //添加前请先查询用户是否存在，如果用户存在，则返回用户已存在。
        //添加对象到数据库前请先补全数据
        //线索添加，默认状态 status 为 1 (数据库已有默认值)
        //把数据新增到数据库即可

        return tbActivityService.add(tbClue);
    }

    @Override
    @GetMapping("list")
    public R list(ClueQueryDto clueQueryDto) {

        return tbClueService.page(clueQueryDto);
    }


}
